/*
 * @lc app=leetcode id=318 lang=cpp
 *
 * [318] Maximum Product of Word Lengths
 */
class Solution {
public:
    int maxProduct(vector<string>& words) {
        vector<int> mask(words.size());
        int result = 0;
        for (int i=0; i<words.size(); i++) {
            for (char c:words[i]) {
                mask[i] |= 1 << (c-'a');
            }

            for (int j=0; j<i; j++){
                if ((mask[i] & mask[j]) == 0) {
                    int len = words[i].size() * words[j].size();
                    result = std::max(result, len);
                }
            }
        }
        return result;
        
    }
};

